home *** CD-ROM | disk | FTP | other *** search
- #ifndef WLIST_INCLUDE
- #define WLIST_INCLUDE 1
- static char SCCS_WLIST_H[] = "@(#)wlist.h 1.1 2/15/94 10:38:14";
- /*+++
-
- wlist.h
-
- PURPOSE : C++ list class definition
-
- DATE : Sat Jan 29 11:41:20 EST 1994
-
- AUTHOR : W. Hatch
-
- PROJECT : WEH Software
-
- COMPANY : Coleman Research Corporation
- 9891 Broken Land Parkway
- Suite 200
- Columbia, Maryland 21045
- Phone (301)621-8600
- FAX (410)7210
- ---*/
- /*
- ------------------------------------------------------------------------
- MODIFICATIONS
- DATE-PROGRAMMER DESCRIPTION
- ------------------------------------------------------------------------
- 2-15-94 W. Hatch added wlist functions ExchangePrevious(),
- ExchangeNext(), Maximum(), Minimum(), Sort(),
- Reverse(), Copy(), SetCompareData()
- */
- #include <string.h>
- #undef TRUE
- #define TRUE 1
- #undef FALSE
- #define FALSE 0
- #undef streql
- #define streql(a,b) (!strcmp((a),(b)))
-
- #define PROBLEM(s) \
- printf("\t%s problem at file %s line %d\n",s,__FILE__,__LINE__)
-
-
- class node{
- private:
- node *previous;
- node *next;
- void *data;
- public:
- node();
- ~node();
- node *PreviousNode();
- node *PreviousNode(node *v);
- node *NextNode();
- node *NextNode(node *v);
- void *NodeData();
- void *NodeData(void *v);
-
- void print(FILE *pf);
- void print();
- };
-
- class wlist {
- private:
- char *name;
- int size;
- node *first;
- node *last;
- node *current;
- void (*PrintData)(FILE *pf, void*);
- int (*CompareData)(void *a, void *b);
- public:
- //----------------------------------------------------------------
- // constructor - set first, last, current to null; name to "noname"
- // set size to zero
- //----------------------------------------------------------------
- wlist();
- //----------------------------------------------------------------
- // destructor - delete each node; delete name
- //----------------------------------------------------------------
- ~wlist();
- //----------------------------------------------------------------
- // Size - return the number of list nodes
- //----------------------------------------------------------------
- int Size();
- //----------------------------------------------------------------
- // DeleteAll - delete all list nodes, set size to zero - does NOT
- // delete the node contents and this is a potential source
- // of memory leakage
- //----------------------------------------------------------------
- void wlist::DeleteAll();
- //----------------------------------------------------------------
- // Name - access and assign list name
- //----------------------------------------------------------------
- char *Name();
- char *Name(char *s);
-
- //----------------------------------------------------------------
- // FirstData - access and assign data in first node; set current to
- // first node; on assign, if list is empty, then AppendData()
- //----------------------------------------------------------------
- void *FirstData();
- void *FirstData(void *v);
-
- //----------------------------------------------------------------
- // LastData - access and assign data in last node; set current to
- // last node; on assign, if list is empty, then AppendData()
- //----------------------------------------------------------------
- void *LastData();
- void *LastData(void *v);
-
- //----------------------------------------------------------------
- // CurrentData - access and assign data in current node;
- // on assign, if list is empty, then AppendData()
- //----------------------------------------------------------------
- void *CurrentData();
- void *CurrentData(void *v);
-
- //----------------------------------------------------------------
- // NextData - access and assign data in next node; set current to
- // next node; on assign, if list is empty, then AppendData()
- // if current is last then AppendData()
- //----------------------------------------------------------------
- void *NextData();
- void *NextData(void *v);
-
- //----------------------------------------------------------------
- // PreviousData - access and assign data in previous node; set
- // current to previous node; on assign, if list is empty,
- // then AppendData(), if current == first then PrependData()
- //----------------------------------------------------------------
- void *PreviousData();
- void *PreviousData(void *v);
-
- //----------------------------------------------------------------
- // AppendData - creates a new node containing the given data and
- // appends this node to end of list; new node becomes the
- // current node
- //----------------------------------------------------------------
- void *AppendData(void *v);
-
- //----------------------------------------------------------------
- // PrependData - creates a new node containing the given data and
- // adds this node to beginning of list; new node becomes
- // the current node
- //----------------------------------------------------------------
- void *PrependData(void *v);
-
- //----------------------------------------------------------------
- // PreInsert - Insert node containing given data before the
- // current node. The new node becomes the current node
- //----------------------------------------------------------------
- void *PreInsert(void *v);
-
- //----------------------------------------------------------------
- // PostInsert - Insert node containing given data after the
- // current node. The new node becomes the current node
- //----------------------------------------------------------------
- void *PostInsert(void *v);
-
- //----------------------------------------------------------------
- // DeleteCurrent - delete the current node. If only one node
- // remains, then this becomes the new current node. If deleted
- // node is the last node, then the new current node is the
- // next to last node. If the deleted node is the first node,
- // then the new current node is the second node. If more
- // than one node remains and an interior node is deleted,
- // then the new current node is the "next node" to the
- // deleted node.
- //----------------------------------------------------------------
- void *DeleteCurrent();
-
- //----------------------------------------------------------------
- // ExchangePrevious() - exchange data between current and previous
- // list nodes; return pointer to new current data
- //----------------------------------------------------------------
- void *ExchangePrevious();
-
- //----------------------------------------------------------------
- // ExchangeNext() - exchange data between current and next list
- // nodes; return pointer to new current data
- //----------------------------------------------------------------
- void *ExchangeNext();
-
- //----------------------------------------------------------------
- // Maximum() - return maximum data; current node is the node
- // containing the maximum
- //----------------------------------------------------------------
- void *Maximum();
-
- //----------------------------------------------------------------
- // Minimum() - return minimum data; current node is the node
- // containing the minimum
- //----------------------------------------------------------------
- void *Minimum();
-
- //----------------------------------------------------------------
- // Sort - create a new list containing the data from this sorted
- // in ascending order. The current node in the new list will
- // be its last node and will contain the pointer to the data
- // that is considered the "largest" by the compare function.
- // This is a brute force implementation. If you want to
- // efficiently sort large lists then the sort algorithm needs
- // more work.
- //----------------------------------------------------------------
- wlist *Sort();
-
- //----------------------------------------------------------------
- // Reverse - reverse order the list
- //----------------------------------------------------------------
- wlist *Reverse();
-
- //----------------------------------------------------------------
- // Copy - create a copy of this; a new wlist is created. Each
- // node of the new list contains the same data pointer as
- // the corresponding node of this. No attempt is made to
- // copy the contents of the data structure pointed to
- // at each node. (This is a level 1 copy.)
- //----------------------------------------------------------------
- wlist *Copy();
-
- //----------------------------------------------------------------
- // SetPrintData - passes the pointer to the data print function
- // to be stored for future reference
- //----------------------------------------------------------------
- void SetPrintData(void (*f)(FILE *pf, void *d));
-
- //----------------------------------------------------------------
- // SetCompareData - pass pointer to the data compare function to
- // be stored for future reference by Sort()
- //----------------------------------------------------------------
- void SetCompareData(int (*f)(void *a, void *b));
- //----------------------------------------------------------------
- // print - used for debug print - assumes all list contents
- // are the same class.
- //----------------------------------------------------------------
- void print(FILE *pf);
- void print();
- };
-
- #endif /* WLIST_INCLUDE */
-